package com.codefactory;

import com.codefactory.generator.param.ProjectConf;
import com.codefactory.generator.param.WritePathConf;
import com.codefactory.generator.service.CodeGenerator;
import com.codefactory.generator.service.GenService;
import com.codefactory.generator.service.ModelService;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.File;
import java.util.Date;

@SpringBootTest
@RunWith(SpringRunner.class)
public class TestGen {
    @Autowired
    private GenService codeGenService;
    @Autowired
    private CodeGenerator codeGenerator;
    @Autowired
    private ModelService modelService;
    private static final String USER_DIR = System.getProperty("user.dir");

    @Test
    public void testGen() throws Exception {
        String now = DateFormatUtils.format(new Date(), "yyyy/MM/dd");
        ProjectConf conf = ProjectConf.builder()
                .projectBasePackage("com.swiftops").packageName("basic.sys")
                .templateClassify("mybatis")
                .templatePath(USER_DIR + "/templates")
                .author("yangyang").date(now)
                .build();
        //conf.put("basePackage", "com.swiftops.basic.sys");

        String path = "C:/Users/yangyang/Desktop/code_dist3";
        WritePathConf pathConf = WritePathConf.builder()
                .controller(path + "/controller")
                .service(path + "/service")
                .serviceImpl(path + "/serviceImpl")
                .mapperJava(path + "/dao")
                .mapperXml(path + "/mapper")
                .modelEntity(path + "/model")
                .voEntity(path + "/vo/entity")
                .voRequest(path + "/vo/request")
                .voResponse(path + "/vo/response")
                .build();
        conf.pathConf = pathConf;

//        CodeGenParam param = CodeGenParam.builder()
//                .tableComment("用户信息").tableName("sys_user")
//                .moduleApi("/api/v1/sys").build();
//        codeGenService.genCode(param, conf);

        File tableNameFile = FileUtils.getFile(USER_DIR, "FTXT", "sys.txt");
        codeGenService.generate(conf, tableNameFile);
    }
}
